<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0">
    <title>新建收货地址</title>
    
    <script src="<%=basePath%>js/fontSize.js"></script>
    <script src="<%=basePath%>js/jquery-1.11.3.min.js"></script>
    <script src="<%=basePath%>js/jsAddress.js"></script>
    
    <link rel="stylesheet" href="<%=basePath%>css/style.css"/>
    <link rel="stylesheet" href="<%=basePath%>css/style2.css"/>
    
    <link rel="stylesheet" href="<%=basePath%>plugins/layer/mobile/need/layer.css"/>
    <script src="<%=basePath%>plugins/layer/mobile/layer.js"></script>
    
    
    <style>
  		body{ background:#F5F5F6;}
  		select {
		  -moz-appearance: none;
		  background: transparent url("http://ourjs.github.io/static/2015/arrow.png") no-repeat scroll right center;
		}
	</style>
</head>

<body>
  <!--头部1-->
  <header class="header3 padding-lr1 background6">
    <p class="header3-left"><a href="<%=basePath%>member/info"><span class="ico bgico-7" style="background-image: url(<%=basePath%>images/img25.png)"></span></a></p>
    <h2 class="header3-title text-align-center color1">我的寻宝</h2>
    <div class="header3-right">
      <figure class="dolamr">
      
        <div class="dolamr-zksq color1">
         	<a href="javascript:void(0)" id="sub">确定</a>
        </div>
      </figure>
    </div>
    
    <div class="clear-both"></div>
  </header>
  <!--/头部1-->
  <div style="border:1px solid #06c1ae;margin:0.5rem;padding:0.3rem 0.5rem;background:#ffffff;font-size:16px;">
  	<label for="name" style="width:12%;float:left;text-align:left;">性名</label>
  	<input type="text" id="name" style="border:0px;width:88%;" value="${shippingAddres.name}" />
  </div>
  <div style="border:1px solid #06c1ae;margin:0.5rem;padding:0.3rem 0.5rem;background:#ffffff;font-size:16px;">
  	<label for="phone" style="width:12%;float:left;text-align:left;">电话</label>
  	<input type="tel" id="phone" style="border:0px;width:88%;" value="${shippingAddres.phone}" />
  </div>
  <div style="border:1px solid #06c1ae;margin:0.5rem;padding:0.3rem 0.5rem;background:#ffffff;font-size:16px;">
  	<label for="province" style="width:12%;float:left;text-align:left;">省</label>
  	<select id="province" style="border:0px;width:88%;"></select>
  </div>
  <div style="border:1px solid #06c1ae;margin:0.5rem;padding:0.3rem 0.5rem;background:#ffffff;font-size:16px;">
  	<label for="city" style="width:12%;float:left;text-align:left;">市</label>
  	<select id="city" style="border:0px;width:88%;"></select>
  </div>
  <div style="border:1px solid #06c1ae;margin:0.5rem;padding:0.3rem 0.5rem;background:#ffffff;font-size:16px;">
  	<label for="area" style="width:12%;float:left;text-align:left;">区</label>
  	<select id="area" style="border:0px;width:88%;"></select>
  </div>
  <div style="border:1px solid #06c1ae;margin:0.5rem;padding:0.3rem 0.5rem;background:#ffffff;font-size:16px;">
  	<label for="address" style="width:12%;float:left;text-align:left;">地址</label>
  	<input type="text" id="address" style="border:0px;width:88%;" value="${shippingAddres.address}"  />
  </div>
  <div style="border:1px solid #06c1ae;margin:0.5rem;padding:0.3rem 0.5rem;background:#ffffff;font-size:16px;">
  	<label for="code" style="width:12%;float:left;text-align:left;">邮编</label>
  	<input type="text" id="code" style="border:0px;width:88%;" value="${shippingAddres.code}" />
  </div>
  <script type="text/javascript">
  	$(function(){
  		
  		areaSelect.createSelect('province', 'city', 'area');
  		
  		$("#province").val("${shippingAddres.province}").change();
  		$("#city").val("${shippingAddres.city}").change();
  		$("#area").val("${shippingAddres.area}");
  		
  		$("#sub").on("click", function() {
  			if (null == $("#name").val() || $("#name").val().trim() == "") {
  				$("#name").focus();
  				layer.open({
  					content: '请输入性名',
  					skin: 'msg',
  					time: 2 //2秒后自动关闭
  				});
  				return;
  			}
  			
  			if (null == $("#phone").val() || $("#phone").val().trim() == "") {
  				$("#phone").focus();
  				layer.open({
  					content: '请输入电话',
  					skin: 'msg',
  					time: 2 //2秒后自动关闭
  				});
  				return;
  			}
  			
  			if (null == $("#province").val() || $("#province").val().trim() == "" || $("#province").val() == "000000") {
  				layer.open({
  					content: '请选择省',
  					skin: 'msg',
  					time: 2 //2秒后自动关闭
  				});
  				return;
  			}
  			
  			if (null == $("#city").val() || $("#city").val().trim() == "" || $("#city").val() == "000000") {
  				layer.open({
  					content: '请选择市',
  					skin: 'msg',
  					time: 2 //2秒后自动关闭
  				});
  				return;
  			}
  			
  			if (null == $("#area").val() || $("#area").val().trim() == "" || $("#area").val() == "000000") {
  				layer.open({
  					content: '请选择区',
  					skin: 'msg',
  					time: 2 //2秒后自动关闭
  				});
  				return;
  			}
  			
  			if (null == $("#address").val() || $("#address").val().trim() == "") {
  				$("#address").focus();
  				layer.open({
  					content: '请输入地址',
  					skin: 'msg',
  					time: 2 //2秒后自动关闭
  				});
  				return;
  			}
  			
  			var id = "${shippingAddres.id}";
  			var ctx = "${pageContext.request.contextPath}";
  			var url = ctx+'/myAddress/add';
  			var data = {};
  			var m = "正在添加收货地址";
  			if (id > 0) {
  				m = "正在修改收货地址";
  				url = ctx+'/myAddress/edit';
  				data = {
  					id : id,
					name : $('#name').val(),
		  	  		phone : $('#phone').val(),
			  	  	code : $('#code').val(),
				  	province : $('#province').val(),
				  	city : $('#city').val(),
				  	area : $('#area').val(),
				  	address : $('#address').val()	
  				}
  			} else {
  				data = {
					name : $('#name').val(),
		  	  		phone : $('#phone').val(),
			  	  	code : $('#code').val(),
				  	province : $('#province').val(),
				  	city : $('#city').val(),
				  	area : $('#area').val(),
				  	address : $('#address').val()	
  				}
  			}
  			//loading带文字
  			var li = layer.open({
  				type: 2,
  				content: m
  			});
  	  		$.ajax({
  	  		    type : "post",
  	  		    url : url,
  	  		    dataType:"json",
  	  		  	data: data,
  	  		    success : function(msg) {
  	  		    	layer.close(li);
  	  		    	layer.open({
  	  					content: msg.msg,
  	  					skin: 'msg',
  	  					time: 2 //2秒后自动关闭
  	  				});
  	  		    	if (msg.code == -1) {
  	  		    		window.location.href = ctx+"/again_login.jsp?page=/member/info";
  	  		    	}
  	  		    	if (msg.code == 1) {
  	  		    		window.location.href = ctx+"/member/info/myAddress";
  	  		    	}
  	  		    }
  	  		});
  		});
  	});
  </script>
</body>
</html>